<template>
  <el-select
    :disabled="disabled"
    :placeholder="place"
    :clearable="clearable"
    :class="className"
    :value="value"
    @change="chioseChange"
  >
    <el-option
      v-for="item in items"
      :key="item.DirKey"
      :label="item.DirName"
      :value="item.DirKey"
    />
  </el-select>
</template>

<script>
import { getDirs } from '@/api/file/userFileDir'
export default {
  props: {
    clearable: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean,
      default: false
    },
    className: {
      type: String,
      default: 'el-input'
    },
    value: {
      default: null
    },
    placeholder: {
      type: String,
      default: '选择字典'
    }
  },
  data() {
    return {
      place: null,
      items: []
    }
  },
  watch: {
    placeholder: {
      handler(val) {
        this.place = val
      },
      immediate: true
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    async load() {
      const list = await getDirs()
      this.items = list
    },
    chioseChange(value) {
      if (value === '') {
        value = null
      }
      this.$emit('input', value)
      this.$emit('change', value)
    }
  }
}
</script>

